package bodyAngle;

import java.util.Date;
import java.text.DateFormat;

public class Angle {

	private double angle;
	private long time;
	private String bodyPlace;
	private double av = 0;
	
	public Angle(double a, long t, String s){
		angle = a;
		time = t;		
		bodyPlace = s;
	}
	
	public Angle(String s){
		this(0,System.currentTimeMillis(), s);
	}
	
	public void setTime(long time) {
		this.time = time;
	}
	public long getTime() {
		return time;
	}
	
	public void setAngle(double angle) {
		this.angle = angle;
	}
	public double getAngle() {
		return angle;
	}
	
	public void setAngularVelocity(long t2, double a2){
		av = (angleInDegrees(a2)-angleInDegrees(angle))/(t2-time);
	}
	public double getAngularVelocity(){
		return av;
	}
	
	public void updateAngularVelocityAndAngle(long t2, double a2){
		//setAngularVelocity(t2,a2);
		
		angle = a2;
		time = t2;		
	}
	
	public long timeInSeconds(){
		return (System.currentTimeMillis() - time) / 1000;
	}
	
	public String timeFormatted(){
		return DateFormat.getTimeInstance().format(new Date(time));
	}
	public double angleInDegrees(double a){
		return a*180.0/3.14159265;
	}	
	
	public String toString(){
		return ""+ timeFormatted()+" " 
				+ bodyPlace +" angle "
				+ angle; //+" degrees, "; 
				//+av+ " d/s"; 
	}
	
}
